<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #content{ 
            width:200px;
            height: 100px;
            border:solid 2px red;

        }
    </style>
</head>
<body>
    <div id="content"></div>

    <script>
        //获取元素
        const content = document.getElementById("content");
        //绑定事件
        content.onmouseover = function(){
            //创建对象
            const xhr = new XMLHttpRequest();
            //初始化 设置类型与url
            xhr.open('POST','http://127.0.0.1:8085/server');
            //设置请求头
            xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
            //设置自定义请求头
            xhr.setRequestHeader('name','suliang')
            //发送  
            // post 传递参数 在xhr.send中传递
            xhr.send('a=100&b=200&c=300');
            //处理数据
            xhr.onreadystatechange = function(){
                if(xhr.readyState == 4){
                    if(xhr.status >= 200 && xhr.status < 300){
                        content.innerHTML = xhr.response;
                    }
                }
            }
            
        }
    </script>
</body>
</html>